//
//  GJEmptyView.m
//  YDGJ
//
//  Created by 黄卫 on 17/2/24.
//  Copyright © 2017年 huangwei. All rights reserved.
//

#import "GJEmptyView.h"
#import "FD_Method.h"
#define GJEmpFontNumber (12.f)

@interface GJEmptyView ()

@property(nonatomic,strong)UILabel *emptyLabel;
@property(nonatomic,strong)UIImageView *emptyImageView;
@property(nonatomic,strong)GJButton *emptyBtn;

@end

@implementation GJEmptyView

+(instancetype)emptyViewWithFrmae:(CGRect)rect AdEmpImageName:(NSString *)imageName AdEmpDesc:(NSString *)desc AdBtnTitle:(NSString *)btnTitle handClickBlock:(void(^)(NSInteger))clickblcok
{
    return [[self alloc]initWithFrame:rect AdEmpImageName:imageName AdEmpDesc:desc AdBtnTitle:btnTitle handClickBlock:clickblcok];
}

-(instancetype)initWithFrame:(CGRect)frame AdEmpImageName:(NSString *)imageName AdEmpDesc:(NSString *)desc AdBtnTitle:(NSString *)btnTitle handClickBlock:(void(^)(NSInteger))clickblcok
{
    if (self = [super initWithFrame:frame])
    {
        UIImage *empImage = [UIImage imageNamed:imageName?:@"icon_list1"];
        self.emptyImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, empImage.size.width, empImage.size.height)];
        self.emptyImageView.image = empImage;
        self.emptyImageView.center = CGPointMake(self.center.x, self.center.y - 64);
        [self addSubview:self.emptyImageView];
        
        self.emptyLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.emptyImageView.frame)+24, self.width, GJEmpFontNumber+1)];
        self.emptyLabel.backgroundColor = [UIColor clearColor];
        self.emptyLabel.text = desc?:@"程序小哥出差啦！";
        self.emptyLabel.textAlignment = NSTextAlignmentCenter;
        self.emptyLabel.font = FontCustomSize(GJEmpFontNumber);
        self.emptyLabel.textColor = UIColorFromRGB(0xa4a4a4);
        [self addSubview:self.emptyLabel];
        
        if (btnTitle.length)
        {
            self.emptyBtn = [GJButton addButtonOnSuperview:self withOrigion:CGPointMake(0, CGRectGetMaxY(self.emptyLabel.frame)+40) width:120 title:btnTitle image:nil clickBlock:^(NSInteger tag)
            {
                if (clickblcok) clickblcok(tag);
            }];
            self.emptyBtn.height = 36;
            self.emptyBtn.centerX = self.centerX;
        }
    }
    return self;
}
-(void)hideViewWithType:(GJHideViewType)type
{
    [self hideSubView:type AdStatus:YES];
}
-(void)resumeWithType:(GJHideViewType)type
{
    [self hideSubView:type AdStatus:NO];
}

-(void)hideSubView:(GJHideViewType)type AdStatus:(BOOL)flage
{
    switch (type)
    {
        case GJHideImageViewType:
        {
            self.emptyImageView.hidden = flage;
            break;
        }
        case GJHideButtonViewType:
        {
            self.emptyBtn.hidden = flage;
            break;
        }
        case GJHideLabelViewType:
        {
            self.emptyLabel.hidden = flage;
            break;
        }
        default:
            break;
    }
    
}


@end
